/**
 * Created by this.alert on 17/8/30.
 */
const ava = require('ava')
const fsp = require('fs-promise')
const app = require('./helpers/app')

const config = require('./helpers/config')
const { success, error } = config

const {
    LEDGER,
} = config.modules

let tag_id
let department_id

ava.serial('[200] add tag', async t => {
    const res = await app
        .post(`${LEDGER}/organization/1/tag`)
        .send({
            title: `test-${Date.now()}`,
            userId: 1
        })
        .ava(t)
    tag_id = res.body.data.tag.id

})

ava.serial('[200] get tag list', async t => {
    const res = await app
        .get(`${LEDGER}/organization/1/tag`)
        .ava(t)
})


ava.serial('[200] add department', async t => {
    const res = await app
        .post(`${LEDGER}/organization/1/department`)
        .send({
            name: `test-${Date.now()}`,
            userId: 1
        })
        .ava(t)
    department_id = res.body.data.department.id
})

ava.serial('[200] get department list', async t => {
    const res = await app
        .get(`${LEDGER}/organization/1/department`)
        .ava(t)
})

ava.serial('[200] del department', async t => {
    console.log(`${LEDGER}/organization/1/department/${department_id}`)
    const res = await app
        .del(`${LEDGER}/organization/1/department/${department_id}`)
        .ava(t)
})

ava.serial('[200] del tag', async t => {
    const res = await app
        .del(`${LEDGER}/organization/1/tag/${tag_id}`)
        .ava(t)
})

//ava.serial('[200] inport ledger', async t => {
//    const res = await app
//        .post(`${APPLICATIONS}/android/example`)
//        .set('token', admin)
//        .field('changeLog', 'Add many bugs.')
//        .field('versionName', Date.now())
//        .field('versionCode', String(Date.now()).replace(/([0-9]{4})([0-9]{4})([0-9])/, '$1.$2.$3'))
//        .field('forceUpgrade', 'true')
//        .attach('file', `${__dirname}/fixtures/test.png`)
//        .ava(t, true)
//})